package com.lz.autotest.common.exception;

import com.lz.autotest.common.domain.ErrMsg;
import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Getter
@Setter
public final class ServiceException extends RuntimeException {

    public final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final long serialVersionUID = 1L;
    //结果标识 0：正常  其他：异常
    private Integer code;
    //错误信息
    private String msg;

    private boolean success;
    //返回结果
    private Object result;
    //自定义返回参数2
    private String sole;

    public ServiceException() {
    }

    public ServiceException(String msg) {
        this.msg = msg;
        this.logger.error("错误信息：{0}", msg);
    }

    public ServiceException(String msg, Integer code) {
        this.msg = msg;
        this.code = code;
        this.logger.error("错误码：{0}，错误信息：{1}", code, msg);
    }

    public ServiceException(ErrMsg errMsg) {
        this.msg = errMsg.getMsg();
        this.code = errMsg.getCode();
        this.logger.error("错误码：{0}，错误信息：{1}", this.code, this.msg);
    }

    public ServiceException(ErrMsg errMsg, String strackMsg) {
        this.msg = errMsg.getMsg() + " " + strackMsg;
        this.code = errMsg.getCode();
        this.logger.error("错误码：{0}，错误信息：{1}", this.code, this.msg);
    }

    public String getMsg() {
        return this.msg;
    }



    public ServiceException setMessage(String msg) {
        this.msg = msg;
        return this;
    }


}
